package Question7;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.Toolkit;

import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;

public class Annonce
  extends JApplet
  implements MouseMotionListener
{
  private int etat = 0;
  private SurfaceDessin surface;
  public Annonce()
  {
  }

  private void jbInit()
    throws Exception
  {
    this.getContentPane().setLayout( null );
  }

  public void init()
  {
    this.addMouseMotionListener(this);
    surface = new SurfaceDessin();
    surface.setSize(this.getWidth(),this.getHeight());
    surface.setLocation(0,0);
    this.getContentPane().add(surface); 
    surface.setVisible(true);
    try
    {
      jbInit();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }

  public static void main(String[] args)
  {
    Annonce applet = new Annonce();
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    frame.getContentPane().add(applet, BorderLayout.CENTER);
    frame.setTitle( "Applet Frame" );
    applet.init();
    applet.start();
    frame.setSize(700, 300);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    frame.setLocation((d.width-frameSize.width)/2, (d.height-frameSize.height)/2);
    frame.setVisible(true);
  }

  public void start()
  {
  }

  public void stop()
  {
  }

  public void destroy()
  {
  }

  public void mouseDragged(MouseEvent e)
  {
  }

  public void mouseMoved(MouseEvent e)
  {
    
    if (e.getXOnScreen()<700 && e.getYOnScreen()<300)
    {
    etat = 1;
    }
    else
    {
    etat =0;  
    }
    
    surface.repaint();
  }
  static {
    try
    {
    }
    catch (Exception e)
    {
    }
  }
  
  public class SurfaceDessin extends JPanel
  {
            protected void paintComponent(Graphics g)
                    {
                      Graphics2D g2 = (Graphics2D)g;
                      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                      
                       super.paintComponent(g);
                
                      g2.setFont(new Font("Tahoma",2,24));
                      g2.drawString("We are Wolves - Invisible Violence",300,25);
                     
                      if (etat == 1)
                      {
                     
                        g2.setColor(Color.RED);
                        
                        g2.setFont(new Font("Tahoma",2,24));
                        g2.drawString("En vente maintenant",350,100); 
                        etat =0;
                      }
                      Image uneImage = getImage(getCodeBase(),"image/image.jpg");
                      
                      g2.drawImage(uneImage,10,10,275,275,this);
                            
                    }
  }
}
